<?php

$container_bl=join('&nbsp;', $form->_button_container['BL']);
$container_br=join('&nbsp;', $form->_button_container['BR']);
$container_tr=join('&nbsp;', $form->_button_container['TR']);

if ($form->_status=='delete' || $form->_action=='delete' || $form->_status=='unknow_record'):
	echo $form->output;
else:

if(isset($form->error_string)) echo '<div class="alert">'.$form->error_string.'</div>';
echo $form_scripts;
echo $form_begin;

if($form->_status!='show'){ ?>

<script language="javascript" type="text/javascript">

$(function(){
	$(".inputnum").numeric(".");
	//totalizar();
});

function totalizar (id,count,check){
	 
 var totals=0;
 var totalg=0;
 var cant=0;
 
  
 var deuda = $("#deuda_"+id).val();
  
 var totals = $("#pago_"+id).val();
 
 var monto  = $("#monto").val();
 
 
 if(check==true){
	var pago= $("#pago_"+id).val(deuda);
 }else{
    var pago= $("#pago_"+id).val(0);
 }
  
  totals = parseFloat(totals);
  monto  = parseFloat(monto);
  cant   = parseInt(cant)
  cant=count+1;
 
 for (var i = 1; i < cant; i++) {
	 
     var totals = $("#pago_"+i).val();
     totals = parseFloat(totals);
     totalg += totals;
     //alert(totalg);
     
 }

  

  //ssubt = totals+monto; 
 
 $("#monto").val(totalg);
 $("#monto_val").text(totalg);
 
}
function totalizar_2 (id,count){
	
 var totals=0;
 var totalg=0;
 var cant=0;
  
 var deuda = $("#deuda_"+id).val();
  
 var totals = $("#pago_"+id).val();
 
 var monto  = $("#monto").val();
  
  totals = parseFloat(totals);
  monto  = parseFloat(monto);
  cant   = parseInt(cant)
  cant=count+1;
 
  //alert (cant);
  
     
 if(totals>deuda)
  alert('Pago mayor a la DEUDA PENDIENTE, Por favor verifique los montos ');
 
 for (var i = 1; i < cant; i++) {
	 
     var totals = $("#pago_"+i).val();
     totals = parseFloat(totals);
     totalg += totals;
     //alert(totalg);
     
 }

 
  //ssubt = totals+monto; 
 
 $("#monto").val(totalg);
 $("#monto_val").text(totalg);
 
}
</script>
<?php } ?>
<table align='center' width="90%" style='background: #EEEEEE'>
	<tr>
		<?php if ($form->_status=='show') { ?>
		<td>
		<a href="#" onClick="window.open('<?php echo base_url() ?>formatos/verhtml/LETRAS/<?php echo $form->id->value ?>', '_blank', 'width=800, height=600, scrollbars=Yes, status=Yes, resizable=Yes, screenx='+((screen.availWidth/2)-400)+',screeny='+((screen.availHeight/2)-300)+'');" heigth="600" >
		<img src='<?php echo base_url() ?>images/html_icon.gif'></a>
		<a href="#" onClick="window.open('<?php echo base_url() ?>formatos/ver/LETRAS/<?php echo $form->id->value ?>', '_blank', 'width=800, height=600, scrollbars=Yes, status=Yes, resizable=Yes, screenx='+((screen.availWidth/2)-400)+',screeny='+((screen.availHeight/2)-300)+'');" heigth="600" >
		<img src='<?php echo base_url() ?>images/pdf_logo.gif'></a> Comprobante 
		</td>
	<?php } ?>
	  <td colspan="3" align="right"><?php echo $container_tr?><?php echo $container_br?></td>
  </tr>
</table>
<table align='center'>
	<tr>
		<td>
         <table align='center' width="95%">
	<tr>
		<td>
		<table width='100%'>
<?php if ($form->_status=='show') { ?>
	<tr>
	<td><a href="#" onclick="window.open('<?php echo base_url() ?>fsiigo/letra/<?php echo $form->id->value ?>', '_blank', 'width=800, height=600, scrollbars=Yes, status=Yes, resizable=Yes, screenx='+((screen.availWidth/2)-400)+',screeny='+((screen.availHeight/2)-300)+'');" heigth="600" ><img src='<?php echo base_url() ?>images/icono_impresora.gif' /></a></td>
	</tr>
<?php } ?>		
		<tr><td>
		<fieldset style='border: 2px outset #9AC8DA;background: #FFFFFF;'>
		<legend class="titulofieldset" style='color: #2E4B77;'>Informaci&ograve;n de la letra</legend>
			<table style="margin: 0; width: 100%;">
			<tr>
				<td class="littletableheader"><?php echo $form->serief->label;    ?></td>
				<td colspan="2" class="littletablerow"><?php echo $form->serief->output;   ?>-<?php echo $form->nnumero->output;   ?></td>
			</tr>
			<tr>
			  <td class="littletableheader"><?php echo $form->control->label     ?></td>
			  <td colspan="2" class="littletablerow"><strong><?php echo $form->control->output    ?></strong></td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->tipo->label;    ?></td>
				<td colspan="2" class="littletablerow"><strong><?php echo $form->tipo->output;   ?></strong></td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->banco->label;    ?></td>
				<td colspan="2" class="littletablerow"><strong><?php echo $form->banco->output;   ?></strong></td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->moneda->label;    ?></td>
				<td colspan="2" class="littletablerow"><?php echo $form->moneda->output;   ?></td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->cuenta->label;    ?></td>
				<td colspan="2" class="littletablerow"><?php echo $form->cuenta->output;   ?></td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->fecha->label;    ?></td>
				<td colspan="2" class="littletablerow">   <?php echo $form->fecha->output;   ?></td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->dias->label;    ?></td>
				<td colspan="2" class="littletablerow">   <?php echo $form->dias->output;   ?></td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->vence->label;    ?></td>
				<td colspan="2" class="littletablerow">   <?php echo $form->vence->output;   ?></td>
			</tr>
			<tr>
			  <td class="littletableheader"><?php echo $form->ncuota->label     ?></td>
			  <td colspan="2" class="littletablerow"><?php echo $form->ncuota->output    ?></td>
			</tr>

			</table>
			</fieldset>
		</td>
		<td width="35%">
			<fieldset style='border: 2px outset #9AC8DA;background: #FFFFFF;'>
			<legend  class="titulofieldset" style='color: #2E4B77;'>Identificaci&oacute;n del Cliente </legend>
			<table  style="margin: 0; width: 100%;">
			<tr>
				<td width="33%" class="littletableheader"><?php echo $form->cod_cli->label;  ?></td>
				<td class="littletablerow"><?php echo $form->cod_cli->output; ?></td>
			</tr>
			<tr>
			  <td class="littletableheader"><?php echo $form->observa->label     ?></td>
			  <td colspan="2" class="littletablerow"><?php echo $form->observa->output    ?></td>
			</tr>
			</table>
			</fieldset>
		</td><tr></table>
		<br>		</td>
	</tr>
	<tr>
		<td>
		<div style='overflow:auto;border: 1px solid #9AC8DA;background: #FAFAFA;height:200px'>
		  <table width='90%' border='0' align="center">
            <tr class="littletablerow" align="center">
				<td colspan='9' align='left'>Facturas Pendientes (<?=$cantmd ?>) <font color="red">ORDENADAS POR FECHA DE VENCIMIENTO</font></td>
            </tr>
            <tr class="littletablerow" align="center">
              <td colspan="2" bgcolor='#527D9E'>Numero FC</td>
              <td bgcolor='#527D9E'>Moneda</td>
              <td bgcolor='#527D9E'>Tipo</td>
              <td bgcolor='#527D9E'>Fecha</td>
			  <td bgcolor='#527D9E'>Vence</td>
              <td bgcolor='#527D9E'>Monto</td>
              <td bgcolor='#527D9E'>Pagos Ralizados</td>
              <td bgcolor='#527D9E'>Deuda Pendiente </td>
              <td bgcolor='#527D9E'>Monto de Letra </td>
            </tr>
		    <? $tmonto=0; $totalg=0; $tabonos=0; $tdeudas=0; $i=0; $count=count($result); foreach ($result AS $items){$i++;?>
            <? $tmonto+=$items->monto ?>
            <? $tabonos+=$items->abonos ?>
            <? $tdeudas+=$items->resta ?>
            <? $resta=$items->resta; ?>
            <? if($form->_status=='show'){ $pago=$items->ultiabonado; ?>
            <? }else{ $pago='0';}?>
            <? $hoy= date('Y-m-d'); ?>
            <? $vencio= $items->vence; ?>
            <? IF($vencio < $hoy){ $vence="<font color='red'>".dbdate_to_human($items->vence)."</font>"; ?>
            <? }else{ $vence=dbdate_to_human($items->vence);  }?>
            <tr>
              <td class="littletablerow" align="center">
				  <input type="checkbox"   id="chek_<?= $i ?>"  onclick="totalizar(<?= $i ?>,<?= $count ?>,this.checked)"  /></td>
				  <td class="littletablerow" align="center">
				  <input type="text"   name="serie[]"  value="<?=$items->serie?>" size="3" readonly="false" />-
				  <input type="text"   name="numero[]" value="<?=$items->numero?>" size="11" readonly="false" />
				  <input type="hidden" name="transac[]" value="<?=$items->transac ?>"/>
				  <input type="hidden" name="cant"   value="<?=$cantmd ?>"/>
				  <input type="hidden" name="idp[]"   value="<?=$items->idp ?>" size="3"/>
              </td>
              </td>
              <td class="littletablerow" align="center"><?= $items->moneda ?></td>
              <td class="littletablerow" align="center"><input type="text" name="tipo2[]"   value="<?=$items->tipo_doc ?>" size="3"/></td>
              <td class="littletablerow" align="left"><?= dbdate_to_human($items->fecha) ?></td>
              <td align="center" class="littletablerow" ><?= $vence ?></td>
              <td class="littletablerow" align='right'><?= nformat($items->monto) ?></td>
              <td align='right' class="littletablerow"><?= nformat($items->abonos) ?></td>
              <td class="littletablerow" align='right'><input id="deuda_<?= $i ?>"  name="deuda_<?= $i ?>" type="text" size="10" value="<?= $resta ?>" readonly="false" align="right"  /></td>
              <td class="littletablerow" align='right'><input id="pago_<?= $i ?>"   name="pago[]"  type="text" size="10" value="<?= $pago ?>" onkeyup="totalizar_2(<?= $i ?>,<?= $count ?>)" align="right" /></td>
			</tr>
            <? }?>
            <tr>
              <td colspan="6" align='right' class="littletablerow" ><strong>Totales</strong></td>
              <td align='right' class="littletablerow"><strong><? echo nformat($tmonto) ?></strong></td>
              <td align='right' class="littletablerow"><strong><? echo nformat($tabonos) ?></strong></td>
              <td class="littletablerow" align='right'><strong><? echo nformat($tdeudas) ?></strong></td>
            </tr>
          </table>
		</div>
		<?php echo $container_bl ?>		</td>
	</tr>
	<tr>
		<td>
		<fieldset style='border: 2px outset #9AC8DA;background: #EFEFEF;'>
		<legend  class="titulofieldset" style='color: #2E4B77;' align="right">-- Monto Total de la LETRA --</legend>
		<table width='100%'>
			<tr>
				<td class="littletableheader" width='100'></td>
				<td class="littletablerow"    width='643' ><?php echo $form->refi->output;  ?></td>
				<td width="170" align='right' class="littletableheader"><?php echo $form->monto->label;  ?></td>
				<td width="153" align='right' class="littletablerow"><strong><b id='monto_val'><input id="monto"   name="monto"  type="text" size="10" readonly="false" value="<?= $form->monto->value;   ?>" /></b></strong></td>
			</tr>
			<tr>
				<td class="littletableheader" width='100'></td>
				<td class="littletablerow"    width='643' ></td>
				<td width="170" align='right' class="littletableheader"><?php echo $form->abono->label;  ?></td>
				<td width="153" align='center' class="littletablerow"><strong><?= $form->abono->value;   ?><strong></td>
			</tr>
		</table>
		</fieldset>	
		</td>
	</tr>
</table>

<?php echo $form_end?>
<?php echo $container_br ?>
	  <td>
	<tr>
<table>
<?php endif; ?>
